package cn.kxm.controller;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;

import cn.kxm.service.StatisticsService;

@Controller
@RequestMapping("/statistics")
public class StatisticsController {
	@Autowired
	private StatisticsService ss;
	
	@RequestMapping("getSaleData")
	@ResponseBody
	public Object getSaleData() {
		List<Map<String, Object>> data=ss.getSaleData();
		
		List<String> month=new ArrayList<String>();
		List<Integer> out_number=new ArrayList<Integer>();
		List<Double> sale_money=new ArrayList<Double>();
		List<Integer> true_number=new ArrayList<Integer>();
		
		for (Map<String,Object> map : data) {
			month.add(map.get("month").toString());
			out_number.add(((BigDecimal)map.get("out_number")).intValue());
			sale_money.add(new Double(map.get("sale_money").toString()));
			true_number.add(((BigDecimal)map.get("true_number")).intValue());
		}
		
		
		Map<String, Object> new_data=new HashMap<String,Object>();
		new_data.put("month", month);
		new_data.put("out_number", out_number);
		new_data.put("sale_money", sale_money);
		new_data.put("true_number", true_number);
		
		return JSON.toJSONString(new_data);
	} 
	@RequestMapping("buynumber")
	@ResponseBody
	public Object buynumber(){
		List<Map<String, Object>> lm=ss.getBuyNumber();//数量
		List<Map<String, Object>> lmap=ss.getBuyPrice();//金额
		
		List<String> partName1=new ArrayList<String>();
		List<String> partName2=new ArrayList<String>();
		List<Integer> amount=new ArrayList<Integer>();
		List<Double> price=new ArrayList<Double>();
		
		for (Map<String, Object> map : lm) {
			partName1.add(map.get("partname").toString());
			amount.add(((BigDecimal)map.get("in_number")).intValue());
		}
		for (Map<String, Object> m : lmap) {
			partName2.add(m.get("partname").toString());
			price.add(new Double(m.get("in_number").toString()));
		}
		
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("partname1", partName1);
		map.put("partname2", partName2);
		map.put("amount", amount);
		map.put("price", price);
		return JSON.toJSONString(map);
	}
	@RequestMapping("sellorNumber_Price")
	@ResponseBody
	public Object sellor(){
		List<Map<String, Object>> lm=ss.getSaleNumber();//数量
		List<Map<String, Object>> lmap=ss.getSalePrice();//金额
		
		List<String> partName1=new ArrayList<String>();
		List<String> partName2=new ArrayList<String>();
		List<Integer> amount=new ArrayList<Integer>();
		List<Double> price=new ArrayList<Double>();
		
		for (Map<String, Object> map : lm) {
			partName1.add(map.get("partname").toString());
			amount.add(((BigDecimal)map.get("out_number")).intValue());
		}
		for (Map<String, Object> m : lmap) {
			partName2.add(m.get("partname").toString());
		}
		
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("partname1", partName1);
		map.put("partname2", partName2);
		map.put("amount", amount);
		map.put("price", price);
		return JSON.toJSONString(map);
	}


@RequestMapping("getPurchaseData")
	@ResponseBody
	public Object getPurchaseData() {
		List<Map<String, Object>> data=ss.getPurchaseData();
		
		List<String> month=new ArrayList<String>();
		List<Integer> purchase_number=new ArrayList<Integer>();
		List<Double> purchase_money=new ArrayList<Double>();
		List<Integer> warehousing_number=new ArrayList<Integer>();
		
		for (Map<String,Object> map : data) {
			month.add(map.get("month").toString());
			purchase_number.add(((BigDecimal)map.get("purchase_number")).intValue());
			purchase_money.add(new Double(map.get("purchase_money").toString()));
			warehousing_number.add(((BigDecimal)map.get("warehousing_number")).intValue());
		}
		
		
		Map<String, Object> new_data=new HashMap<String,Object>();
		new_data.put("month", month);
		new_data.put("purchase_number", purchase_number);
		new_data.put("purchase_money", purchase_money);
		new_data.put("warehousing_number", warehousing_number);
		
		return JSON.toJSONString(new_data);
	} 
}
